<!--
 * @Author: hucc
 * @Date: 2021-10-13 19:24:00
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-13 20:21:29
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router.js"></script>
    <script src='../js/jquery.js'></script>
</head>

<body>
    <div id="app">
        账号：<input type="text"><br> 密码：
        <input type="password"><br>
        <my-com>
            <template #default='login'>
               <button></button>
            </template>
        </my-com>
        <router-view></router-view>
    </div>
    <script>
        // $('button').click(function() {
        let obj = {
            username: 'admin1',
            password: '123321'
        }
        $.ajax({
                url: ' http://47.94.46.113:8888/user/login',
                method: 'post',
                data: JSON.stringify(obj),
                headers: {
                    'Content-Type': 'application/json'
                },
                success(res) {
                    console.log(res);
                    sessionStorage.setItem('token', res.data.token);
                }
            })
            // })
            //注册组件
        let component1 = {
                data() {
                    return {
                        login: ''
                    }
                },
                methods: {
                    clickHandler() {
                        this.$router.push({
                            path: '/index.html'
                        })
                    }
                },
                template: `
                <div>
                     
                     <button :login='login' @click='clickHandler'>登录</button>
                    </div>
             `
            }
            //定义路由
        let router = new VueRouter({
            routes: [{
                path: './index.html',
                component: component1
            }]
        })
        new Vue({
            el: '#app',
            data: {},
            methods: {

            },
            //注册路由
            router: router,
            components: {
                'my-com': component1
            }
        })
    </script>
</body>

</html>